package com.bdqn;

import com.bdqn.pojo.News;
import com.bdqn.service.NewsService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * TestNewsService
 *
 * @author LILIBO
 * @since 2024/7/13
 */
public class TestNewsService {

    public static void main(String[] args) {
        // 加载Spring上下文环境
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 从Spring环境中获取一个Beans实例
        NewsService newsService = (NewsService) context.getBean("newsServiceImpl");
        System.out.println(newsService);
        newsService.save(new News());
        // NewsService newsService2 = (NewsService) context.getBean("newsServiceImpl");
        // System.out.println(newsService2);
        // 默认Spring获取到Bean的实例是单例的
        // System.out.println(newsService == newsService2);
    }

}
